package General;

public class MembershipMatrix {
	
	private int n;
	private int c;
	private double mat [][];
	
	public MembershipMatrix (int nodes, int clusters)
	{
		c=clusters;
		n=nodes;
		mat = new double [clusters][nodes];
	}
	
	public int getNumberOfClusters()
	{
		return c;
	}
	
	public double get (int i, int k)
	{
		return mat [k][i];
	}
	
	public void set (int i, int k, double value)
	{
		mat [k][i]=value;
	}
	
	public void merge (int k, int l)
	{
		for (int i=0; i<n; i++)
			mat[k][i]+=mat[l][i];
		remove(l);
	}
	
	private void remove (int k)
	{
		for (int i=0; i<n; i++)
			mat[k][i]=mat[c-1][i];
		c--;
		mat[c]=null;
	}

	public void print()
	{
		System.out.println("\nMEMBERSHIP MATRIX:");
		for (int i=0; i<c; i++)
		{
			
			for (int j=0; j<n; j++)
				System.out.printf("%4.4f ", get(j,i));
			System.out.println();
		}
	}
	
	public String toString()
	{
		String s = "MEMBERSHIP MATRIX: \n";
		for (int i=0; i<c; i++)
		{
			
			for (int j=0; j<n; j++)
				s+= get(j,i)+" ";
		s+="\n";
		
		}
		
		return s;
	}
}
